package com.shuoyue.ycgk.views.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.utils.SizeUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 *
 */

public class SelectPayTypetDialog extends Dialog {

    @BindView(R.id.wx_pay)
    CheckBox wxPay;
    @BindView(R.id.lay_wx)
    LinearLayout layWx;
    @BindView(R.id.alpay)
    CheckBox alpay;
    @BindView(R.id.lay_ali)
    LinearLayout layAli;
    @BindView(R.id.lay_pay)
    LinearLayout layPay;
    @BindView(R.id.tv_cancel)
    TextView tvCancel;
    @BindView(R.id.tv_ok)
    TextView tvOk;
    private Context mContext;

    SelectedCallBack callBack;

    public SelectPayTypetDialog(@NonNull Context context, SelectedCallBack callBack) {
        super(context, R.style.dialog);
        this.mContext = context;
        this.callBack = callBack;
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(context, R.layout.dialog_select_pay_type, null);
        setContentView(view);
        ButterKnife.bind(this, view);
        getWindow().setLayout((SizeUtil.getScreenWidth(mContext) * 3) / 4, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setGravity(Gravity.CENTER);
    }

    @OnClick({R.id.wx_pay, R.id.lay_wx, R.id.alpay, R.id.lay_ali, R.id.tv_cancel, R.id.tv_ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.wx_pay:
            case R.id.lay_wx:
                alpay.setChecked(false);
                wxPay.setChecked(true);
                break;
            case R.id.alpay:
            case R.id.lay_ali:
                alpay.setChecked(true);
                wxPay.setChecked(false);
                break;
            case R.id.tv_cancel:
                dismiss();

                break;
            case R.id.tv_ok:
                if (callBack != null && wxPay.isChecked()) {
                    callBack.selected(1);
                } else if (callBack != null && alpay.isChecked()) {
                    callBack.selected(2);
                }
                break;
        }
    }


    public interface SelectedCallBack {
        void selected(int type);
    }
}
